package imgsei.wcj.com.medalmodule.view;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.Button;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import imgsei.wcj.com.commonbusiness.base.activity.BaseActivity;
import imgsei.wcj.com.commonbusiness.utils.LogUtils;
import imgsei.wcj.com.commonbusiness.utils.RouteUtils;
import imgsei.wcj.com.medalmodule.R;
import imgsei.wcj.com.medalmodule.R2;
import imgsei.wcj.com.medalmodule.bean.WeatherInfoBean;
import imgsei.wcj.com.medalmodule.presenter.WeatherPresenterImp;


/**
 * 勋章首页
 *
 * @ author LUCKY
 * @ create date 2018/11/7 09:15
 */
@Route(path = RouteUtils.MEDA_HOME)
public class MainMedalActivity extends BaseActivity implements WeatherView{
    private static final String TAG = "MainMedalActivity";
    private Unbinder unbinder;

    @BindView(R2.id.go_to_activity)
    Button goToActivity;
    @BindView(R2.id.go_back)
    Button goBack;
    @BindView(R2.id.medal_text)
    TextView medalText;

    private WeatherPresenterImp weatherPresenterImp = null;
    private ProgressDialog progressDialog;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_medal);
        unbinder = ButterKnife.bind(this);
        ARouter.getInstance().inject(this);


        weatherPresenterImp = new WeatherPresenterImp(this,this);
        progressDialog = new ProgressDialog(this);
        progressDialog.setMessage("LOADING...");
    }
    @OnClick(R2.id.go_to_activity)
    public void toActivity(){
        LogUtils.showLogD(TAG,"toActivity");
        if (weatherPresenterImp!=null){
            Map<String,String> params = new HashMap<>();
            params.put("grant_type","password");
            params.put("client_id","system");
            params.put("client_secret","13ed77c1d8291cef388aa8a6ff6ddc3e");
            params.put("login_type","password");
            params.put("username","18600000000");
            params.put("password","111111");
            weatherPresenterImp.loadWeather(params);
        }
        //helloService.sayHello("老王");
//        Bundle params = new Bundle();
//        params.putString("name","老王");
//        int width = UiUtils.getScreenWidth(this);
//        int height = UiUtils.getScreenHeight(this);
//        View v = getWindow().getDecorView();
//        ActivityOptionsCompat compat = ActivityOptionsCompat.
//                    makeScaleUpAnimation(v, width / 2,
//                            height / 2, 0, 0);
//        ARouter.getInstance().build(RouteUtils.ACTIVITY_HOME).with(params).withOptionsCompat(compat).navigation();

    }
    @OnClick(R2.id.go_back)
    public void gotoBack(){
        LogUtils.showLogD(TAG,"gotoBack");
        finish();
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (unbinder != null) {
            unbinder.unbind();
        }
    }

    @Override
    public void showProgress() {
        if(progressDialog != null && !progressDialog.isShowing()){
            progressDialog.show();
        }
    }

    @Override
    public void hideProgress() {
        if(progressDialog != null && progressDialog.isShowing()){
            progressDialog.dismiss();
        }
    }

    @Override
    public void loadDataSuccess(WeatherInfoBean data) {
        if (data!=null){
            WeatherInfoBean.BooksBean booksBean=data.getBooks().get(0);
            medalText.setText(booksBean.getAlt_title());
        }
    }

    @Override
    public void loadDataError(Throwable throwable) {
        LogUtils.showLogE(TAG,throwable.getMessage());
    }
}
